package com.showdor.datasource;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 * @author chuan
 */
@Configuration
public class DatabaseConfig {

    @Bean(name = "x185sourceDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.x185source")
    public HikariDataSource x185sourceDataSource() {
        return DataSourceBuilder.create().type(HikariDataSource.class).build();
    }

    @Bean(name = "x185sourceJdbcTemplate")
    public JdbcTemplate x185sourceJdbcTemplate(@Qualifier("x185sourceDataSource") HikariDataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

    @Bean(name = "y186targetDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.y186target")
    public HikariDataSource y186targetDataSource() {
        return DataSourceBuilder.create().type(HikariDataSource.class).build();
    }

    @Bean(name = "y186targetJdbcTemplate")
    public JdbcTemplate y186targetJdbcTemplate(@Qualifier("y186targetDataSource") HikariDataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

    @Bean(name = "y186sourceDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.y186source")
    public HikariDataSource y186sourceDataSource() {
        return DataSourceBuilder.create().type(HikariDataSource.class).build();
    }

    @Bean(name = "y186sourceJdbcTemplate")
    public JdbcTemplate y186sourceJdbcTemplate(@Qualifier("y186sourceDataSource") HikariDataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

    @Bean(name = "x185targetDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.x185target")
    public HikariDataSource x185targetDataSource() {
        return DataSourceBuilder.create().type(HikariDataSource.class).build();
    }

    @Bean(name = "x185targetJdbcTemplate")
    public JdbcTemplate x185targetJdbcTemplate(@Qualifier("x185targetDataSource") HikariDataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }
}